#define _CRT_SECURE_NO_WARNINGS 1
class Solution {
public:
    vector<int> searchRange(vector<int>& nums, int target) {
        vector<int> ret;
        int begin = -1, end = -1;
        if (nums.empty())
        {
            ret.push_back(begin);
            ret.push_back(end);
            return ret;
        }
        int left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int min = left + (right - left) / 2;
            if (nums[min] < target)
            {
                left = min + 1;
            }
            else if (nums[min] >= target)
            {
                right = min;
            }
        }
        if (nums[right] == target)
        {
            begin = right;
        }
        left = 0, right = nums.size() - 1;
        while (left < right)
        {
            int min = left + (right - left + 1) / 2;
            if (nums[min] <= target)
            {
                left = min;
            }
            else if (nums[min] >= target)
            {
                right = min - 1;
            }
        }
        if (nums[left] == target)
        {
            end = left;
        }
        ret.push_back(begin);
        ret.push_back(end);
        return ret;
    }
};